<template>
  <view class="bottom-button">
    <view class="left-icon">
      <view class="iconfont icon-a-24_nor primary" @tap="back" />
      <view class="iconfont icon-shouye2 primary" @tap="toHome" />
      <slot name="leftIcon"></slot>
    </view>
    <view v-if="isRightBtn" class="right-btn" @tap="$emit('rightClick')"> {{ rightText }}</view>
  </view>
</template>
<script setup lang="ts" name="BottomButton">
export interface BottomButtonProps {
  rightText?: string; // 右侧按钮文字
  modalVisible?: boolean;
  isRightBtn?: boolean; // 是否显示右侧按钮
}
// 接受父组件参数，配置默认值
withDefaults(defineProps<BottomButtonProps>(), {
  rightText: "新增",
  modalVisible: false,
  isRightBtn: true
});
// const keyupSubmit = (e: KeyboardEvent) => {
//   if (e.key === "Enter" && !props.modalVisible && props.isRightBtn) {
//     $emit("rightClick");
//   }
// };
// // 绑定回车键事件
// useEventListener(keyupSubmit);

const $emit = defineEmits(["rightClick"]);

const back = () => {
  uni.navigateBack();
};

const toHome = () => {
  uni.redirectTo({
    url: "/pages/home/index"
  });
};
</script>
<style lang="scss" scoped src="./index.scss"></style>
